<template>
  <div class="order-item">
    <div class="title">
      <div class="name">{{ orderData.unitName }}</div>
      <div class="status">{{ orderData.orderStatusDesc }}</div>
    </div>
    <div class="content">
      <img class="cover" :src="orderData.unitPicture" alt="" />
      <div class="bottom">
        <div class="left">
          <div class="date start-date">
            <div class="day">{{ formatMonthWeek(orderData.checkInDate) }}</div>
            <div class="week-time">
              <div class="week">
                {{ formatMonthWeek(orderData.checkInDate, true) }}
              </div>
              <div class="time">{{ orderData.checkInLatestTime }}</div>
            </div>
          </div>
          <img
            class="arrow"
            src="@/assets/img/order/icon_right_orderlist.png"
            alt=""
          />
          <div class="date end-date">
            <div class="day">{{ formatMonthWeek(orderData.checkOutDate) }}</div>
            <div class="week-time">
              <div class="week">
                {{ formatMonthWeek(orderData.checkOutDate, true) }}
              </div>
              <div class="time">{{ orderData.checkOutLatestTime }}</div>
            </div>
          </div>
        </div>
        <div class="right">
          <div class="text">支付总价</div>
          <div class="price">￥{{ orderData.prepayAmount }}</div>
        </div>
      </div>
    </div>
    <div class="btn">
      <div class="left" v-if="orderData.orderStatus === 1">
        <img src="@/assets/img/order/icon-time.png" alt="" />
        <span class="time">{{ remainingTime }}分</span>
        <span class="msg">后订单自动取消</span>
      </div>
      <div class="right">
        <button v-if="orderData.orderStatus === 1" class="btn connect">
          联系房东
        </button>
        <button v-if="orderData.orderStatus === 1" class="btn pay">
          去支付
        </button>

        <button v-if="orderData.orderStatus === 5" class="btn delete">
          删除
        </button>
        <button v-if="orderData.orderStatus === 5" class="btn order">
          再次预定
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";

import { formatMonthWeek } from "@/utils/format_date";

defineProps({
  orderData: {
    type: Object,
    default: () => {},
  },
});

const remainingTime = ref(0);
</script>

<style lang="less" scoped>
.order-item {
  padding: 0 20px;
  margin-top: 10px;
  background-color: #fff;

  .title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;

    .name {
      max-width: 204px;
      font-size: 12px;
      color: #333;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
    }

    .status {
      font-size: 18px;
      color: var(--primary-color);
      font-weight: 600;
    }
  }

  .content {
    height: 223px;
    width: 100%;
    position: relative;

    .cover {
      width: 100%;
      height: 100%;
      border-radius: 6px;
    }

    .bottom {
      position: absolute;
      bottom: 0;
      right: 0;
      left: 0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      background-color: rgba(9, 10, 14, 0.7);
      border-radius: 0 0 6px 6px;
      height: 60px;
      font-size: 12px;
      color: #fff;

      .left {
        display: flex;
        align-items: center;

        .arrow {
          width: 16px;
          height: 12px;
        }

        .date {
          display: flex;
          flex-direction: column;
          align-items: center;

          .day {
            font-size: 16px;
            padding-bottom: 5px;
          }

          .week-time {
            display: flex;
            font-size: 12px;
            opacity: 0.8;
          }
        }

        .start-date {
          padding: 0 20px;
        }

        .end-date {
          padding: 0 15px 0 20px;
          border-right: 1px solid;
        }
      }

      .right {
        padding-right: 20px;

        .text {
          opacity: 0.8;
          font-size: 14px;
          padding-bottom: 5px;
        }

        .price {
          color: var(--primary-color);
          font-size: 16px;
        }
      }
    }
  }

  .btn {
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    font-size: 12px;

    .left {
      img {
        width: 11px;
        height: 11px;
        margin-right: 5px;
      }

      .time {
        color: var(--primary-color);
      }

      .msg {
        color: #666;
      }
    }

    .right {
      display: flex;
      align-items: center;

      .btn {
        display: inline-block;
        text-align: center;
        height: 30px;
        line-height: 30px;
        margin-left: 10px;
        font-size: 14px;
        min-width: 75px;
        color: #666;
        background: #fff;
        border: 1px solid #e9e9e9;
        border-radius: 6px;
      }

      .connect {
      }
      .pay {
        color: white;
        background-color: var(--primary-color, #ff9645);
        border: 1px solid var(--primary-color, #ff9645);
      }
      .delete {
      }
      .order {
        color: var(--primary-color, #ff9645);
        background-color: #fff;
        border: 1px solid var(--primary-color, #ff9645);
      }
    }
  }
}
</style>
